# Copyright (C) Nicola Bizzoca   2006/2007  <hannibal_smith@users.sourceforge.net>
# Copyright (C) Simone Economo   2006/2007  <ekoes@users.sourceforge.net>
# 
#    This file is part of Absynth-FTP.
#
#    Absynth-FTP is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 3 of the License, or
#    (at your option) any later version.
#
#    Absynth-FTP is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

import gtk
from engine import Widgets
import TreeView, DownloadView

class UI(Widgets, DownloadView.dwCore):
    def __init__(self):
        DownloadView.dwCore.__init__(self)
        Widgets.__init__(self)
        self.notebook = self.XMLtree.getWidget("MiscBox")
        
        self.tree = TreeView.genericTreeView()
        self.tree.createTree("Tree", {
            "headers-visible"  : True,
            "headers-clickable": True,
            "rows-search"      : False,
            "rows-same-height" : False,
            "rows-alternate"   : True,
            "rows-reorder"     : True,
        })
        
        self.tree.setColumns([
            ("Filename", "image", str, True, True),
            ("Size", "text", str, True, False, 50),
            ("Sended", "text", str, True, True, None),
            ("Filename-text", "text", str, False, False, None, 0),
            ("Progress", "progress", float, True, True, None) ])
        
        self.tree.renderers[0].set_property('xalign', 1.0)
        self.tree.columns[0].set_sort_column_id(3)
        
        scroll = gtk.ScrolledWindow()
        scroll.add_with_viewport(self.tree.widget)
        scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scroll.show()
        self.tree.widget.show()
        tabLabel = gtk.Label("Uploads")
        
        self.index = self.notebook.append_page(scroll, tabLabel)
    
    def append_session(self, data):
        self.tree.addTreeRow([
            'folder', None, None, data['name'], 0 ])
        data['ftp'].connect('newUpload', self.append_file)
        data['ftp'].connect('upProgress', self.updateProgress)
        data['ftp'].connect('endUpload', self.removeFromTree)
        data['ftp'].connect('failUpload', self.removeFromTree)
        self.connection.append({
                                'ftp' : data['ftp'],
                                'iter' : len(self.tree.iters)-1})
    